package com.cashmama.market.api.application.controller.website;

import com.alibaba.fastjson.JSONObject;
import com.cashmama.market.api.application.annos.SignIgnore;
import com.cashmama.market.api.application.annos.VisitorAccessible;
import com.cashmama.market.api.domain.service.ApiUserService;
import com.cashmama.market.api.domain.vo.user.UserPromotionVo;
import com.cashmama.market.api.infras.config.ApolloConfigUtil;
import com.cashmama.market.api.infras.handler.ApiResponse;
import com.cashmama.market.api.infras.handler.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: market-api
 * @description 官网使用
 * @author: frank
 * @create: 2020-01-08 11:25
 **/
@RestController
@RequestMapping("/website/")
public class WebSiteController {

    @Autowired
    private ApolloConfigUtil apolloConfigUtil;

    @Autowired
    private ApiUserService apiUserService;
    /**
     * 官网产品列表
     * @return
     */
    @SignIgnore
    @VisitorAccessible
    @RequestMapping(value = "/product/list")
    public ApiResponse websiteProductList() {
        return new ApiResponse<>(JSONObject.parseObject(apolloConfigUtil.getWebSiteProductList()));
    }

    /**
     * 官网用户行为
     * @return
     */
    @SignIgnore
    @VisitorAccessible
    @RequestMapping(value = "/promotion/add")
    public ApiResponse<ResponseData> websitePromotionAdd(@RequestBody UserPromotionVo promotionVo) {
        apiUserService.addPromotion(promotionVo);
        return new ApiResponse<>("Success");
    }
}
